<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>修德抄经堂</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<link rel="stylesheet" type="text/css" href="../bower_components/mui/dist/css/mui.css">
	<script src="../bower_components/mui/dist/js/mui.min.js"></script>
	<script src="../bower_components/jquery/dist/jquery.min.js"></script>
	<script src="../js/common.js"></script>
	<script src="../js/resLoader.js"></script>
	<script src="../js/mui.picker.js"></script>
	<script src="../js/mui.poppicker.js"></script>
	<script src="../js/city.data.js"></script>
	<script src="../js/city.data-3.js"></script>
	<link rel="stylesheet" type="text/css" href="../css/base.css">
	<link rel="stylesheet" type="text/css" href="../css/full.css">
	<link rel="stylesheet" type="text/css" href="../css/add_address.css">
	<link rel="stylesheet" type="text/css" href="../css/mui.picker.css">
	<link rel="stylesheet" type="text/css" href="../css/mui.poppicker.css">	
</head>
<body>
	<div class="page">
		<div id="content">
			<table class="fang">
				<tr>
					<td style="padding-left: 10px;" width="100">
						省市区县
					</td>
					<td style="padding-right: 10px;">
						<input id="showCityPicker1" type="text" placeholder="请输入所在地区">
					</td>
				</tr>
				<tr>
					<td valign="top" style="padding-left: 10px; padding-top:6px;" width="100">
						详细地址
					</td>
					<td style="padding:0 10px;">
						<textarea id="textarea" placeholder="需填写楼栋楼层或房间号信息" name="" rows="" cols=""></textarea>
					</td>
				</tr>
				<tr>
					<td style="padding-left: 10px;">
						联系人
					</td>
					<td style="padding-right: 10px;">
						<input id="name" type="text" placeholder="请输入联系人姓名">
					</td>
				</tr>
				<tr>
					<td style="padding-left: 10px;">
						联系方式
					</td>
					<td style="padding-right: 10px;">
						<input id="dianhua" type="number" placeholder="请输入联系人手机号码">
					</td>
				</tr>
			</table>
			
			<button type="submit" id="queren" class="same">确认</button>
		</div>
		
		<div id="fugai"></div>
		<p id="wanshan" class="fang">请完善信息</p>
	</div>
</body>
<script>
	mui.init();
</script>
<script>
	(function($, doc) {
		$.init();
		$.ready(function() {
			var cityPicker3 = new $.PopPicker({
				layer: 3
			});
			cityPicker3.setData(cityData3);
			var show_sheng = doc.getElementById('showCityPicker1');
			show_sheng.addEventListener('tap', function(event) {
				cityPicker3.show(function(items) {
					if((items[2] || {}).text == undefined){
						show_sheng.value=(items[0] || {}).text + "    " + (items[1] || {}).text;
					}else{
						show_sheng.value=(items[0] || {}).text + "    " + (items[1] || {}).text + "    " + (items[2] || {}).text;						
					}
				});
			}, false);
		});
	})(mui, document);
	
	$('#queren').click(function(){
		if($("#showCityPicker1").val()=="" || $("#name").val()=="" || $("#dianhua").val()=="" || $('#textarea').val()=="" || !(/^1[34578]\d{9}$/.test($("#dianhua").val()))){
			$("#fugai,#wanshan").show();
		}else{
            var csrftoken = getCookie('csrftoken');
            var address = $('#showCityPicker1').val() + $('#textarea').val();
            var name = $('#name').val();
            var phone = $('#dianhua').val();

            console.log(address)
            $.ajax({
                url: '/fe/user/address_list',
                type: 'POST',
                data: {
                    "address": address,
                    "contact": name,
                    "phone": phone,
                },
                beforeSend: function(xhr, settings) {
                    xhr.setRequestHeader("X-CSRFToken", csrftoken);
                },
                success: function (data) {
					console.log(data);

					var returnUrl = getUrlParam("returnUrl");
					if (!returnUrl){
						returnUrl = "benxin_address.html";
					}
                    window.location.href = returnUrl;
                }

            })
			//window.location.href="benxin_address.html?backurl="+window.location.href;
		}
	})
	$("#fugai,#wanshan").click(function(){
		$("#fugai,#wanshan").hide();
	});

	var h=$(window).height();
    $(window).resize(function() {
        if($(window).height()<h){
            $('#queren').hide();
        }
        if($(window).height()>=h){
            $('#queren').show();
        }
    });
    function getCookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]);
        return null;
    }
    $('#queren').click(function () {

    })

</script>
</html>
